import axios from "axios";
import { useEffect, useState } from "react";

export interface MenuState {
  id: string
  image: string
  title: string
}

export function useFetchMenus() {
  // 1. 容器
  const [banners, setBanner] = useState<MenuState[]>([])

  // 2. 请求
  const fetchBanners = async () => {
    const resp = await axios.get('/api/menus');
    setBanner(resp.data.data)
  }

  // 3. 副作用函数
  useEffect(() => {
    fetchBanners()
  }, [])

  // 4. 返回
  return banners
}